<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/1.9.0/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/1.9.0/themes/icon.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/1.9.0/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/1.9.0/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/1.9.0/locale/easyui-lang-zh_CN.js"></script>

    <script type="text/javascript">


        <!-- 条件查询用户start -->

        function searchUser(){
            $("#tt").datagrid("load",{
                borrowerPhone:$("#searchBorrowerPhone").val(),
                // tenderId:$("#searchTenderId").val(),
                tenderTitle:$("#searchTenderTitle").val(),
                // productId:$("#searchProductId").val(),
                investorPhone:$("#searchInvestorPhone").val()
            });
        }

        <!-- 条件查询用户 end -->

        function formatTender(val,row){
            var columnName = this.field;
            if (row.tender){
                if(columnName == "tenderId" && row.tender.tenderId){
                    return row.tender.tenderId;
                }
                else if(columnName == "tenderTitle" && row.tender.tenderTitle){
                    return row.tender.tenderTitle;
                }
                else if(columnName == "borrowerPhone" && row.tender.borrowerPhone){
                    return row.tender.borrowerPhone;
                }
            }

        }


        function formatBuyRecord(val,row){
            var columnName = this.field;
            if(row.buyRecord){
                 if(columnName == "buyAmount" && row.buyRecord.buyAmount){
                     return row.buyRecord.buyAmount;
                 }
                 else if(columnName == "investorPhone" && row.buyRecord.investorPhone){
                     return row.buyRecord.investorPhone;
                 }

             }
        }

        function formatProduct(val,row){
            var columnName = this.field;

                if(columnName == "productId" && row.productId){
                    return row.productId;
                }
                else if(columnName == "productType" && row.productType){
                    if(row.productType == 1){
                        return '翼农计划';
                    }
                    else if(row.productType == 2){
                        return '私人定制';
                    }
                    else if(row.productType == 3){
                        return '芝麻开花';
                    }
                    else if(row.productType == 4){
                        return '翼农计划+';
                    }
                    else {
                        return row.productType;
                    }
                }

            // if(row.buyRecord){
            //     if(columnName == "productId" && row.buyRecord.productId){
            //             return row.buyRecord.productId;
            //     }
            //     else if(columnName == "productType" && row.buyRecord.productType){
            //         if(row.buyRecord.productType == 1){
            //             return '翼农计划';
            //         }
            //         else if(row.buyRecord.productType == 2){
            //             return '私人定制';
            //         }
            //         else {
            //             return row.buyRecord.productType;
            //         }
            //     }
            //
            // }

        }



        function formatOperate(value,row,index){
            // var idType;
            // var id;
            // if(row.tender){
            //     if(row.tender.tenderId) {
            //         id = row.tender.tenderId;
            //         idType = "tenderId";
            //     }
            // }
            // else if(row.buyRecord){
            //     if(row.buyRecord.productId){
            //         id = row.buyRecord.productId;
            //         idType = "prodctId";
            //     }
            // }
            // alert("id：" + id);
            // alert("idType：" + idType);
            // return '<a href="javascript:void(0)" onclick="openDetails(' + id + ',\'' + idType + '\')">详情</a>';
            var isTenderNull;
            if(row.tender){
                isTenderNull = 0;//不为空
            }
            else{
                isTenderNull = 1;//为空
            }
            var isBuyRecordNull;
            if(row.buyRecord){
                isBuyRecordNull = 0;//不为空
            }
            else{
                isBuyRecordNull = 1;//为空
            }
            var isProductNull;
            if(row.productId){
                isProductNull = 0;//不为空
            }
            else{
                isProductNull = 1;//为空
            }
            return '<a href="javascript:void(0)" onclick="openDetails(' + index + ',' + isTenderNull +',' + isBuyRecordNull +',' + isProductNull + ')">详情</a>';
        }

        function openDetails(index, isTenderNull,isBuyRecordNull, isProductNull){
            // alert("isTenderNull：" + isTenderNull);
            //1.选中一行
            $("#tt").datagrid("selectRow",index);
            //2.获取行信息
            var row = $("#tt").datagrid("getSelected");

            <!-- 如果有标信息 -->
            if(isTenderNull == 0) {

                var t_status;
                if(row.tender.status){
                    if(row.tender.status == 30){
                        t_status = "推送债券池";
                    }
                }

                $("#fm").form("load", {
                    tenderId: row.tender.tenderId,
                    tenderTitle: row.tender.tenderTitle,
                    borrowerName: row.tender.borrowerName,
                    borrowerPhone: row.tender.borrowerPhone,
                    t_status: t_status,
                    t_errorMessage: row.tender.errorMessage,
                });

                $("#dlg-tenderTb").show();
            }else{
                $("#dlg-tenderTb").hide();
            }

            <!-- 如果有购买记录信息 -->
            if(isBuyRecordNull == 0){
                $("#fm").form("load", {
                    investorPhone: row.buyRecord.investorPhone,
                    buyAmount: row.buyRecord.buyAmount,
                    r_status: row.buyRecord.status,
                    r_errorMessage: row.buyRecord.errorMessage,
                });
                $("#dlg-buyTb").show();
            }else{
                $("#dlg-buyTb").hide();
            }

            <!-- 如果有产品信息 -->
            if(isProductNull == 0){
                $("#dlg-productTb").show();
            }else{
                $("#dlg-productTb").hide();
            }

            <!-- 加载产品信息 -->
            $("#fm").form("load", {

                productId: row.productId,
                productName: row.productName,
                productType: row.productType,
                periodClose: row.periodClose,
                status: row.status,
                errorMessage: row.errorMessage
            });
            //3.打开编辑窗口
            $("#dlg").dialog("open").dialog("setTitle","数据详情");

        }

        function closeDetailsDlg(){
            $("#dlg").dialog("close");
        }

    </script>

    <style type="text/css">
        .onlyRead{
            background-color:#F5F5F5
        }
        .multilineTextBox{
            width:480px;height:100px
        }
    </style>
</head>
<body>

    <!-- 数据显示 -->
    <table id="tt" class="easyui-datagrid"
           title="全流程数据管理"
           fitColumns="true"
           fit="true"
           rownumbers="true"
           pagination="true"
           url="${pageContext.request.contextPath}/wholeProcess2/selectAll"
           pageSize="10"
           pageList="[10,20,30,40,50]"
           toolbar="#tb"
           striped="true"
    >
        <thead>
        <tr>
<%--            <th field="cb" checkbox="true" align="center"></th>--%>
            <th field="borrowerPhone" width="50" align="center" sortable="true" formatter="formatTender">借款人手机号</th>
            <th field="tenderId" width="50" align="center" sortable="true" formatter="formatTender">借款ID</th>
            <th field="tenderTitle" width="50" align="center" sortable="true" formatter="formatTender">借款名称</th>
            <th field="productId" width="50" align="center" sortable="true" formatter="formatProduct">产品ID</th>
<%--            <th field="e" width="50" align="center" sortable="true">产品名称</th>--%>
            <th field="productType" width="50" align="center" sortable="true" formatter="formatProduct">产品类型</th>
<%--            <th field="investorPhone" width="50" align="center" sortable="true" formatter="formatBuyRecord">投资人手机号</th>--%>
<%--            <th field="a" width="50" align="center" sortable="true">更新时间</th>--%>
            <th field="b" width="50" align="center" sortable="true">状态</th>
<%--            <th field="c" width="50" align="center" sortable="true">报错信息</th>--%>
            <th field="z" width="50" align="center" sortable="true" formatter="formatOperate">操作</th>
        </tr>
        </thead>
    </table>
    <div id="tb">
        <div>
            &nbsp;借款人手机号：<input type="text" id="searchBorrowerPhone" name="searchBorrowerPhone" size="20">
<%--            &nbsp;标id：        <input type="text" id="searchTenderId" name="searchTenderId" size="20">--%>
            &nbsp;标名称：      <input type="text" id="searchTenderTitle" name="searchTenderTitle" size="20">
<%--            &nbsp;产品id：      <input type="text" id="searchProductId" name="searchProductId" size="20">--%>
<%--            &nbsp;投资人手机号：      <input type="text" id="searchInvestorPhone" name="searchInvestorPhone" size="20">--%>
            <a href="javascript:searchUser()" class="easyui-linkbutton" iconCls="icon-search" plain="true">查询</a>
        </div>
    </div>


    <!-- 查看对话框 -->
    <div id="dlg" class="easyui-dialog"
         style="padding:10px 10px;width:700px;"
         closed="true"
         buttons="#dlg-buttons">
        <form id="fm" method="post">

            <table border="0px" width="600px" id="dlg-tenderTb">
                <tr>
                    <td colspan="4"><b>发标</b></td>
                </tr>
                <tr>
                    <td>借款ID</td>
                    <td>
                        <input type="text" id="tenderId" name="tenderId" class="textbox onlyRead" readonly="true" >
                    </td>
                    <td>借款标题</td>
                    <td>
                        <input type="text" id="tenderTitle" name="tenderTitle" class="textbox onlyRead" readonly="true" >
                    </td>
                </tr>
                <tr>
                    <td>借款人姓名</td>
                    <td><input type="text" id="borrowerName" name="borrowerName" class="textbox onlyRead" readonly="true"  ></td>
                    <td>借款人手机号</td>
                    <td><input type="text" id="borrowerPhone" name="borrowerPhone" class="textbox onlyRead" readonly="true"  ></td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td><input type="text" id="t_status" name="t_status" class="textbox onlyRead" readonly="true" ></td>
                </tr>
                <tr>
                    <td></td>
                </tr>
                <tr>
                    <td>失败原因</td>
                    <td colspan="3"><input type="text" id="t_errorMessage" name="t_errorMessage" class="textbox onlyRead multilineTextBox" readonly="true"></td>
                </tr>
                <tr>
                    <td colspan="4">
                        <hr style="height:1px;border:none;border-top:1px solid #555555;" />
                    </td>
                </tr>
            </table>
            <table width="600px" id="dlg-productTb">
                <tr>
                    <td colspan="4"><b>发布产品</b></td>
                </tr>
                <tr>
                    <td>产品ID</td>
                    <td><input type="text" id="productId" name="productId" class="textbox onlyRead" readonly="true"  ></td>
                    <td>产品名称</td>
                    <td><input type="text" id="productName" name="productName" class="textbox onlyRead" readonly="true"  ></td>
                </tr>
                <tr>
                    <td>产品类型</td>
                    <td><input type="text" id="productType" name="productType" class="textbox onlyRead" readonly="true"  ></td>
                    <td>产品封闭期</td>
                    <td><input type="text" id="periodClose" name="periodClose" class="textbox onlyRead" readonly="true"  ></td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td><input type="text" id="status" name="status" class="textbox onlyRead" readonly="true" ></td>
                </tr>
                <tr>
                    <td>失败原因</td>
                    <td colspan="3"><input type="text" id="errorMessage" name="errorMessage" class="textbox onlyRead multilineTextBox" readonly="true" ></td>
                </tr>
                <tr>
                    <td colspan="4">
                        <hr style="height:1px;border:none;border-top:1px solid #555555;" />
                    </td>
                </tr>
            </table>

            <table width="600px" id="dlg-buyTb">
                <tr>
                    <td colspan="4"><b>购买产品</b></td>
                </tr>
                <tr>
                    <td>投资人手机号</td>
                    <td><input type="text" id="investorPhone" name="investorPhone" class="textbox onlyRead" readonly="true"  ></td>
                    <td>购买金额</td>
                    <td><input type="text" id="buyAmount" name="buyAmount" class="textbox onlyRead" readonly="true"  ></td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td><input type="text" id="r_status" name="r_status" class="textbox onlyRead" readonly="true" ></td>
                </tr>
                <tr>
                    <td>失败原因</td>
                    <td colspan="3"><input type="text" id="r_errorMessage" name="r_errorMessage" class="textbox onlyRead multilineTextBox" readonly="true" ></td>
                </tr>
                <tr>
                    <td colspan="4">
                        <hr style="height:1px;border:none;border-top:1px solid #555555;" />
                    </td>
                </tr>
            </table>

<%--            <table width="600px" id="dlg-InterTb">--%>
<%--                <tr>--%>
<%--                    <td colspan="4"><b>产品计息</b></td>--%>
<%--                </tr>--%>
<%--                <tr>--%>
<%--                    <td>状态</td>--%>
<%--                    <td><input type="text" id="i_status" name="i_status" class="textbox onlyRead" readonly="true" ></td>--%>
<%--                </tr>--%>
<%--                <tr>--%>
<%--                    <td>失败原因</td>--%>
<%--                    <td colspan="3"><input type="text" id="i_errorMessage" name="i_errorMessage" class="textbox onlyRead" readonly="true" ></td>--%>
<%--                </tr>--%>

<%--            </table>--%>
        </form>
    </div>

    <div id="dlg-buttons">
        <a href="javascript:closeDetailsDlg()" class="easyui-linkbutton" iconCls="icon-cancel">取消</a>
    </div>

</body>
</html>
